﻿using System.Web;
using System.Web.Mvc;
using Orchard.Mvc.Html;

namespace Amba.ImageMultiPicker.HtmlHelpers
{
    public static class HtmlHelperExtensions
    {
        public static string PluralNumber(this HtmlHelper helper, int count, string arg0, string arg1, string arg2, string arg3)
        {
            var result = arg0;
            var lastDigit = count % 10;
            var lastTwoDigits = count % 100;
            if (lastDigit == 1 && lastTwoDigits != 11)
            {
                result += arg1;
            }
            else if ((lastDigit == 2 && lastTwoDigits != 12)
                     || (lastDigit == 3 && lastTwoDigits != 13)
                     || (lastDigit == 4 && lastTwoDigits != 14))
            {
                result += arg2;
            }
            else
            {
                result += arg3;
            }
            return result;
        }

        public static IHtmlString IfElse(this HtmlHelper helper, bool condition, string ifTrueValue, string elseValue)
        {
            if (condition)
            {
                return helper.Raw(ifTrueValue);
            }
            return helper.Raw(elseValue);
        }

        public static IHtmlString HideIfTrue(this HtmlHelper helper, bool condition)
        {
            if (condition)
            {
                return helper.Raw(@"style=""display:none;""");
            }
            return new HtmlString("");
        }

        public static IHtmlString IfTrue(this HtmlHelper helper, bool condition, string value)
        {
            if (condition)
            {
                return helper.Raw(value);
            }
            return new HtmlString("");
        }

        public static string ThemePath(this HtmlHelper htmlHelper, string path)
        {
            var theme = htmlHelper.GetWorkContext().CurrentTheme;
            var url = htmlHelper.ThemePath(theme, path);
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            return urlHelper.Content(url);
        }
    }
}